package com.loveprogrammer.eternity.skill.support.skills;

import com.loveprogrammer.eternity.enums.AttackTypeEnum;
import com.loveprogrammer.eternity.enums.WeaponTypeEnum;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.model.Monster;
import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.model.attack.AttackEntity;
import com.loveprogrammer.eternity.model.attack.AttackResult;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0.0
 * @description: 致命打击
 * @author: eric
 * @date: 2022-08-11 16:49
 **/
public class SkillDeathAttack extends AbstractSkill {

    public SkillDeathAttack(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    public boolean check(Character character) {
        if(character instanceof Monster){
            return true;
        }
        // 检查武器类型
        return checkWeaponType(character,WeaponTypeEnum.DAGGER);
    }

    @Override
    public int opportunityPassive() {
        // 0为 主动技能
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每4级升一级
        if(characterLevel % 4 == 0){
            return true;
        }
        return false;
    }

    /***
     * 发动技能
     **/
    @Override
    public Tuple<String, List<Character>> skillLaunch(Character character,
                                                      List<? extends Character> attack,
                                                      List<? extends Character> defences) {
        Tuple<String, List<Character>> tuple = new Tuple();
        // 按照血量排序，攻击血量最低的
        Character defence = findSingleAttacker(defences,true);

        StringBuilder builder = new StringBuilder();
        builder.append(character.getName()).append("(").append(character.getCurrentHp()).append("/")
                .append(character.getHpMax()).append(")").append(" 使用技能[")
                .append(getName()).append(" ").append(getLevel()).append("级】攻击了 ").append(defence.getName());
        int power = getHarm(character);

        // 必定暴击
        boolean crit = true;
        power = power * 2;

        AttackResult attackResult = defence.defence(new AttackEntity(this, power, AttackTypeEnum.NORMAL));
        computeHarm(builder,crit,defence,attackResult, character, attack, defences);
        // defence.checkDead();
        List<Character> value = new ArrayList<>();
        value.add(defence);
        tuple.setKey(builder.toString());
        tuple.setValue(value);
        return tuple;
    }

    @Override
    protected int computeHarm(Character character) {
        return  (int) (character.getStrength() * 0.7 + character.getTechnique() * 0.7 + getLevel() * 100);
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }
}
